<?php
/*
*	Kleophatra - Open Source Content Management System
*	------------------------------------------------------------------------
*	Copyright (C) 2007-2009, Sergio Milardovich <smilardovich@yahoo.com.ar>
*	This program is Free Software.
*	Kleophatra XML parser
*
*	@package	Kleophatra
*	@subpackage	/lib
*	@license	http://www.gnu.org/copyleft/gpl.html GNU/GPL License 2.0
*	@author		Sergio Milardovich <smilardovich@yahoo.com.ar>
*	@link		http://www.kleophatra.org
*	@author		Matías Parodi <mparodilabs@gmail.com>
*	@link		http://mparodi.com
*/

class kleoxmlparser extends kleotemplate{

	function xml_load($xml_file){
 		if(file_get_contents($xml_file)){
			return file_get_contents($xml_file);
		} else {
		  $this->apperror('the file does NOT exists', 'common');
		}
	}

	function xml_getcontent($element, $xml_content) {
		if (preg_match('/<'.$element.'.*>(.+)<\/'.$element.'>/', $xml_content, $matches)){
			return $matches[1];
		} else {
			return false;
		}
	}

	function xml_getattrib($element, $xml_content){

		if (empty($attrib)) {
			if (preg_match('|<'.$element.'([^>]+)|', $xml_content, $element_attribs)) {
				preg_match_all('|([^\s=]+)="([^"]+)"|', $element_attribs[1], $element_subattribs);
					foreach ($element_subattribs[1] as $key => $value) {
						$attribs[$value] = $element_subattribs[2][$key];
					}
					return $attribs;
			} else {
				return false;
			}
		} else {
			if (preg_match('|<'.$element.'.+' . $attrib . '="([^"]+)"|', $xml_content, $attrib_value)) {
				return $attrib_value[1];
			} else {
				return false;
			}
		}

	}


}

?>